# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=yarl
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.9.2
pkgrel=2
pkgdesc='Yet another URL library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/aio-libs/yarl/"
license=('Apache')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-idna"
  "${MINGW_PACKAGE_PREFIX}-python-multidict"
  "${MINGW_PACKAGE_PREFIX}-python-typing_extensions")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-cython"
  "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
source=("https://github.com/aio-libs/yarl/archive/v${pkgver}/yarl-${pkgver}.tar.gz")
sha256sums=('b4a3203470cdc231da67914cadafa1f76fcd29a06557a924e7e165721663693c')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  sed 's| .install-cython ||g' -i Makefile
  make cythonize
  LANG=en_US.UTF-8 ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  LANG=en_US.UTF-8  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
